package com.example.databasepj.controller;

import com.example.databasepj.Request.AdminAddMerchantRequest;
import com.example.databasepj.Request.AdminAddUserRequest;
import com.example.databasepj.Request.MerchantUpdateRequest;
import com.example.databasepj.dto.AdminMerchantData;
import com.example.databasepj.dto.AdminUserData;
import com.example.databasepj.dtoAdvanced.UserActivityRequest;
import com.example.databasepj.dtoAdvanced.UserActivityResponse;
import com.example.databasepj.dtoAdvanced.UserFeatureRequest;
import com.example.databasepj.dtoAdvanced.UserFeatureResponse;
import com.example.databasepj.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/admin")
public class AdminController {
    @Autowired
    private AdminService adminService;

    @GetMapping("/GetUserList") //获取所有用户信息
    @ResponseBody
    public List<AdminUserData> getUserList(){
        return adminService.getAllUsers();
    }

    @GetMapping("/GetMerchantList") //获取所有商户信息
    @ResponseBody
    public List<AdminMerchantData> getMerchantList(){
        return adminService.getAllMerchants();
    }

    @PostMapping("/DeleteMerchant/{merchant_ID}")//删除一个商户
    @ResponseBody
    public void deleteMerchant(@PathVariable int merchant_ID) {
        adminService.deleteMerchant(merchant_ID);
    }

    @PostMapping("/DeleteUser/{user_ID}")//删除一个用户
    @ResponseBody
    public void deleteUser(@PathVariable int user_ID) {
        adminService.deleteUser(user_ID);
    }

    @PostMapping("/AddMerchant")//添加一个商户
    @ResponseBody
    public void addMerchant(@RequestBody AdminAddMerchantRequest request) {
        adminService.insertMerchant(request);
    }

    @PostMapping("/AddUser")//添加一个用户
    @ResponseBody
    public void addUser(@RequestBody AdminAddUserRequest request) {
        adminService.insertUser(request);
    }

    @PutMapping ("/updateMerchant/{merchant_ID}") //管理员修改商户信息
    @ResponseBody
    public void updateMerchant(@PathVariable int merchant_ID,
                               @RequestBody MerchantUpdateRequest request){
        adminService.updateMerchant(merchant_ID,request);
    }
    @PostMapping("/userActivity")//用户活跃度分析
    @ResponseBody
    public List<UserActivityResponse> userActivity(@RequestBody UserActivityRequest request) {
        return adminService.userActivity(request);
    }

    @PostMapping("/userCharacteristics")//用户特征分析
    @ResponseBody
    public List<UserFeatureResponse> userCharacteristics(@RequestBody UserFeatureRequest request) {
        return adminService.getUserFeature(request);
    }



}
